package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.iview.IItemView;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.TypeUtils;
import com.yaozheng.vocationaltraining.widget.TextProgressBar;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 一项上次学习记录
 *
 * @author Administrator
 */
@EViewGroup(R.layout.item_last_academic_records)
public class LastAcademicRecordsItemView extends LinearLayout {
//	TextProgressBar itemLastAcademicRecordsTextProgressBar;
    /**
     * 标题
     */
    @ViewById
    TextView LastAcademicRecordsTitleItemText;
    @ViewById
    ImageView coursewareImage;
    @ViewById
    LastLearnStatusProgressView lastLearnStatusProgressView;
    int position;

    IItemView iItemView;

    public LastAcademicRecordsItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public LastAcademicRecordsItemView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public void init(IItemView iItemView) {
        this.iItemView = iItemView;
    }

    public void loadData(int position, JSONObject courseJsonObject, BitmapLoader bitmapLoade) {
        this.position = position;
        // if (position % 3 == 0) {
        // itemLastAcademicRecordsTextProgressBar.setProgressText(20,
        // "学习进度：20%");
        // } else if (position % 3 == 1) {
        // itemLastAcademicRecordsTextProgressBar.setProgressText(50,
        // "学习进度：50%");
        // } else {
        // itemLastAcademicRecordsTextProgressBar.setProgressText(70,
        // "学习进度：70%");
        // }
        int progress = TypeUtils.getJsonInteger(courseJsonObject, "percent");
        lastLearnStatusProgressView.setProgress(progress);
//		itemLastAcademicRecordsTextProgressBar.setProgressText(progress,
//				"学习进度：" + progress + "%");
        LastAcademicRecordsTitleItemText.setText(TypeUtils.getJsonString(
                courseJsonObject, "courseSubject"));
        if (bitmapLoade != null) {
            bitmapLoade.displayImage(TypeUtils.getJsonString(
                    courseJsonObject, "courseImage2"), coursewareImage);
        }
    }

    /**
     * 复习点击
     */
    @Click(R.id.itemRootView)
    public void reviewClick() {
        if (iItemView != null) {
            iItemView.itemClick(position);
        }
        // if (position % 2 == 0) {
        // Intent intent = new Intent();
        // intent.putExtra("title", "销售");
        // intent.setClassName(getContext(),
        // Constants.VIDEO_COURSEWARE_DETAIL_ACTIVITY_CLASS_NAME);
        // getContext().startActivity(intent);
        // } else {
        // Intent intent = new Intent();
        // intent.putExtra("title", "销售");
        // intent.setClassName(getContext(),
        // Constants.IMAGE_LIST_COURSEWARE_DETAIL_ACTIVITY_CLASS_NAME);
        // getContext().startActivity(intent);
        // }
    }
}
